/*
 * MP3_Beaney - The MP3 Tag Editor is a free ID3-Tag Editor
 * Copyright (C) 2012 Bernhard Teismann, André Seipelt, Steffen Gruschka, Imanuel Rohlfing
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details. 
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
package uInterface;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

/**
 * Panel for path selection.
 *
 * @author Steffen Gruschka
 * @author Bernhard Teismann
 * @author André Seipelt
 * @author Imanuel Rohlfing
 * @version 1.0
 */
public class Step1 extends javax.swing.JPanel {

    /**
     * Creates new form Step1
     */
    public Step1(){
        initComponents();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Step1Panel = new javax.swing.JPanel();
        Step1OpenTextField = new javax.swing.JTextField();
        Step1OpenButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setPreferredSize(new java.awt.Dimension(987, 400));

        Step1Panel.setBackground(new java.awt.Color(255, 255, 255));
        Step1Panel.setName("Schritt1");
        Step1Panel.setPreferredSize(new java.awt.Dimension(770, 349));

        Step1OpenTextField.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N

        Step1OpenButton.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
        Step1OpenButton.setText("Öffnen");
        Step1OpenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Step1OpenButtonActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Rockwell", 0, 16)); // NOI18N
        jLabel1.setText("Öffnen Sie einen Ordner oder eine Datei");

        org.jdesktop.layout.GroupLayout Step1PanelLayout = new org.jdesktop.layout.GroupLayout(Step1Panel);
        Step1Panel.setLayout(Step1PanelLayout);
        Step1PanelLayout.setHorizontalGroup(
            Step1PanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, Step1PanelLayout.createSequentialGroup()
                .addContainerGap(152, Short.MAX_VALUE)
                .add(Step1PanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(Step1PanelLayout.createSequentialGroup()
                        .add(Step1OpenTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 417, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(Step1OpenButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 99, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(85, 85, 85))
        );
        Step1PanelLayout.setVerticalGroup(
            Step1PanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, Step1PanelLayout.createSequentialGroup()
                .addContainerGap(129, Short.MAX_VALUE)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(Step1PanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(Step1OpenTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(Step1OpenButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(116, 116, 116))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(69, 69, 69)
                .add(Step1Panel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 759, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(159, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(23, 23, 23)
                .add(Step1Panel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 303, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(74, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Setter for the MainInterface
     * <p/>
     * @param mi the MainInterface
     */
    public void setMainInterface(MainInterface mi){
        MainInterface = mi;
    }

    /**
     * Getter for the Texfield.
     * <p/>
     * @return a String with the Text
     */
    public String getTextFromTextfild(){
        return Step1OpenTextField.getText();
    }

    @SuppressWarnings("unchecked")
    private void load(){
        JFileChooser choose = new JFileChooser();

        choose.setDialogTitle("Musikordner auswaehlen");
        choose.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        choose.setFileFilter(new FileFilter() {

            @Override
            public String getDescription(){
                return ".mp3 Files";
            }

            @Override
            public boolean accept(File f){
                return f.isDirectory() || f.getName().toLowerCase().endsWith(".mp3");
            }
        });
        choose.setAcceptAllFileFilterUsed(false);
        if (choose.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){
            Step1OpenTextField.setText(choose.getSelectedFile().getAbsolutePath());
        }
    }

    private void Step1OpenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Step1OpenButtonActionPerformed
        /*
         * Opens JFileChooser
         */
        load();
    }//GEN-LAST:event_Step1OpenButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Step1OpenButton;
    private javax.swing.JTextField Step1OpenTextField;
    private javax.swing.JPanel Step1Panel;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables
    private MainInterface MainInterface;
}
